#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int flag[110];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		memset(flag,0,sizeof(flag));
		int l,r;
		scanf("%d %d",&l,&r);
		int ans = 0;
		for(int i = 1;i<n;i++)
		{
			int x,y;
			scanf("%d %d",&x,&y);
			for(int j = x;j<y;j++)
			{
				flag[j] = 1;
			}
		}
		for(int i = l;i<r;i++)
		{
			if(!flag[i]) ans++;
		}
		printf("%d\n",ans);
	}
}
